/* 需求：
   鼠标移入a标签，点亮背景图标，显示文本
   鼠标移出a标签，回到原来状态
 */

 //获取a标签

 let adom = document.querySelectorAll('#online a')
//  console.log(adom);

//遍历
adom.forEach( function ( va ){
    // console.log( va );

    //移入
    va.addEventListener('mouseover', function(){
        va.style.backgroundPositionX = '-50px'
        va.style.transition = '0.3s'
        this.querySelector('span').style.width = "150px"
        this.querySelector('span').style.right = "50px"
        this.querySelector('span').style.opacity = "1"
        
    })

    //移出
    va.addEventListener('mouseout', function(){
        va.style.backgroundPositionX = '0'
        va.style.transition = '0.3s'
        this.querySelector('span').style.width = "50px"
        this.querySelector('span').style.opacity = "0"
    })


    window.onscroll = function scrollFunction(){
        // console.log(200)
        if(document.body.scrollTop > 200 || document.documentElement.scrollTop > 200){
           document.getElementById('fh').style.height = '50px'
        }else{
           document.getElementById('fh').style.height = '0px'
        }
    }

    let fh = document.getElementById('fh')

    // fh.addEventListener('click' , function(){
       
    //     //计时器开始
    //     let mytime = setInterval( function(){
    //         //获取每30毫秒后的滚动初始值
    //         let sTop = document.documentElement.scrollTop

    //         //运动4
    //         document.documentElement.scrollTop = sTop - 50

    //        //判断
    //        if( sTop <= 0){

    //         //停止计时器
    //          clearInterval( mytime )
    //        }

    //     }, 30)
    // })


    fh.addEventListener('click' , function(){

        //设置运动的总时间
        let zsj = 1000;  //单位 ms

        //获得总路程
        let lc = document.documentElement.scrollTop

        //得到运动速度
        let sd = lc / zsj
       
        //计时器开始
        let mytime = setInterval( function(){
        
        //每50毫秒的运动起点
        let sTop = document.documentElement.scrollTop
        
        //运动50ms
        document.documentElement.scrollTop = sTop - 50*sd
        //判断
        if( sTop <= 0 ){
           //停止计时器
           clearInterval( mytime )
        }

        }, 50)
    })


})



// let nv = document.getElementById('nv')
// // console.log(nv);

// window.onscroll = function scrollFunction(){
//     // console.log(200)
//     if(document.body.scrollTop > 100 || document.documentElement.scrollTop > 100){
//        document.getElementById('nv').style.position = 'fixed'
//        document.getElementById('nv').style.width = '100%'
//        document.getElementById('nv').style.background = '#fff'
//        document.getElementById('nv').style.zIndex = '999'
//        document.getElementById('nv').style.boxShadow = '0px 0px 15px #3e3e3e'
       
//     }else{
//        document.getElementById('nv').style.position = 'relative'
//        document.getElementById('nv').style.boxShadow = 'none'
//     }
// }

